<template>
  <div class="hello-world">
    <h2>{{ title }}</h2>
    <div v-if="showInput">
      <input 
        v-model="inputText" 
        :placeholder="placeholder"
        class="input-field"
      />
      <button 
        v-if="showClearButton" 
        @click="clearInput" 
        class="clear-button"
      >
        清空
      </button>
    </div>
    <div v-if="displayOutput" class="output-area">
      <p>{{ inputText }}</p>
    </div>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  props: {
    title: {
      type: String,
      default: 'HelloWorld组件'
    },
    showInput: {
      type: Boolean,
      default: true
    },
    showClearButton: {
      type: Boolean,
      default: true
    },
    displayOutput: {
      type: Boolean,
      default: false
    },
    placeholder: {
      type: String,
      default: '请输入内容'
    }
  },
  data() {
    return {
      inputText: ''
    }
  },
  methods: {
    clearInput() {
      this.inputText = '';
      this.$emit('cleared');
    }
  }
}
</script>

<style scoped>
.hello-world {
  border: 1px solid #e74c3c;
  padding: 15px;
  margin: 15px 0;
  border-radius: 4px;
}

.input-field {
  padding: 8px;
  width: 100%;
  margin-bottom: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.clear-button {
  padding: 6px 12px;
  background-color: #f8f9fa;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
}

.output-area {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  min-height: 40px;
}
</style>